from django.db import models
#
# class Question(models.Model):
#     DIMENSION_CHOICES = [
#         ('EI', '外向-内向'),
#         ('SN', '实感-直觉'),
#         ('TF', '思考-情感'),
#         ('JP', '判断-感知'),
#     ]
#
#     DIRECTION_CHOICES = [
#         ('E', '外向'),
#         ('I', '内向'),
#         ('S', '实感'),
#         ('N', '直觉'),
#         ('T', '思考'),
#         ('F', '情感'),
#         ('J', '判断'),
#         ('P', '感知'),
#     ]
#
#     text = models.TextField()
#     order = models.IntegerField(unique=True)
#     dimension = models.CharField(max_length=2, choices=DIMENSION_CHOICES)
#     direction = models.CharField(max_length=1, choices=DIRECTION_CHOICES)
#     weight = models.IntegerField(default=1)  # 题目权重
#     created_at = models.DateTimeField(auto_now_add=True)
#
#     def __str__(self):
#         return f"{self.order}. {self.text[:50]}..."

class Question(models.Model):
    text = models.TextField()
    order = models.IntegerField(unique=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.order}. {self.text[:50]}..."

class TestSession(models.Model):
    session_key = models.CharField(max_length=40, unique=True)
    created_at = models.DateTimeField(auto_now_add=True)
    completed = models.BooleanField(default=False)
    mbti_result = models.CharField(max_length=4, blank=True, null=True)

class Answer(models.Model):
    session = models.ForeignKey(TestSession, on_delete=models.CASCADE)
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    value = models.IntegerField()  # -3到3，表示同意程度
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        unique_together = ('session', 'question')